package org.krishna.spring.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class LMSContoller {

	
	private static final Logger LOGGER = LoggerFactory
			.getLogger(LMSContoller.class);

	
	private static final ObjectMapper objectMapper = new ObjectMapper();

	public Object getJavaObjectFromJson(String json, TypeReference<?> tf) {
		objectMapper.configure(
				DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		objectMapper
				.configure(
						DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
						true);
		Object jsonJavaObj = null;
		try {
			jsonJavaObj = objectMapper.readValue(json, tf);
		} catch (Exception e) {
			LOGGER.error("Exception occured While parsing the given json string : "	+ json, e);

		}
		if (LOGGER.isDebugEnabled())
			LOGGER.debug("json::: " + json);
		return jsonJavaObj;

	}

}
